package com.cn.zpark;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @PackageName: com.cn.zpark
 * @ClassName: CookieDemo01
 * @Description:
 * @author: RZS
 * @date: 2022/4/13  11:03
 */
@WebServlet("/cook1")
public class CookieDemo01 extends HttpServlet {
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 创建cookie对象
        Cookie cook1 = new Cookie("C1", "youSeeSeeYou");
        Cookie cook2 = new Cookie("javaWEB", "noeDayDayDe");

        // 设置cookie失效时间，单位秒
        cook1.setMaxAge(60);

        // 将Cookie信息添加到响应信息中
        response.addCookie(cook1);
        response.addCookie(cook2);

    }
}
